moneyLook.DB.addRepay = function(_note, _montant, _contact)
	{
		var db = Ti.Database.open('moneylook2');
		db.execute("INSERT INTO moneybook (note, montant, insertdate, from_contact, to_contact) VALUES (?, ?, ?, ?, ?)", 
			_note, _montant, new Date().getTime(), null, _contact);
			
		db.close();
		
		Ti.App.fireEvent("databaseUpdated");
	};
	
	moneyLook.DB.addRepayWithGeo = function(_note, _montant, _contact, _longitude, _latitude)
	{
		var db = Ti.Database.open('moneylook2');
		db.execute("INSERT INTO moneybook (note, montant, insertdate, from_contact, to_contact, longitude, latitude) VALUES (?, ?, ?, ?, ?, ?, ?)", 
			_note, _montant, new Date().getTime(), null, _contact, _longitude, _latitude);
			
		db.close();
		
		Ti.App.fireEvent("databaseUpdated");
	};
	
	moneyLook.DB.addRepayWithAll = function(_note, _montant, _contact, _longitude, _latitude, _imgPath)
	{
		var db = Ti.Database.open('moneylook2');
		db.execute("INSERT INTO moneybook (note, montant, insertdate, from_contact, to_contact, longitude, latitude, imgPath) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", 
			_note, _montant, new Date().getTime(), null, _contact, _longitude, _latitude, _imgPath);
			
		db.close();
		
		Ti.App.fireEvent("databaseUpdated");
	};
	
	
	moneyLook.DB.getDetailRepay = function(id)
	{
		var db = Ti.Database.open('moneylook2');
		var rows = db.execute("SELECT * FROM moneybook WHERE to_contact IS NOT null AND to_contact != '' AND id == ?", id);
		
		var data;
		
		if(rows.isValidRow())
		{
			data = {
				id:rows.getFieldByName('id'),
				note: rows.getFieldByName('note'),
				montant: Number(rows.getFieldByName('montant')),
				date: Number(rows.getFieldByName('insertdate')),
				from: rows.getFieldByName('from_contact'),
				to: rows.getFieldByName('to_contact'),
				longitude: rows.getFieldByName("longitude"),
				latitude: rows.getFieldByName("latitude"),
				imgPath: rows.getFieldByName("imgPath")
			};
		}
		
		rows.close();
		db.close();
		
		return data;
	};
	
	moneyLook.DB.getDetailExpense = function(id)
	{
		var db = Ti.Database.open('moneylook2');
		var rows = db.execute("SELECT * FROM moneybook WHERE id = ?", id);
		
		
			var data = {
				id:rows.getFieldByName('id'),
				note: rows.getFieldByName('note'),
				montant: Number(rows.getFieldByName('montant')),
				date: Number(rows.getFieldByName('insertdate')),
				from: rows.getFieldByName('from_contact'),
				to: rows.getFieldByName('to_contact'),
				longitude: rows.getFieldByName("longitude"),
				latitude: rows.getFieldByName("latitude"),
				imgPath: rows.getFieldByName("imgPath")
			};
		
		rows.close();
		db.close();
		
		return data;
	};